import DCOracle2
import common
import unittest

class test_blob(common.TestCase):

    tables_to_drop = ('blobtest',)
    
    def test_blob(self):
        c = self.c
        c.execute("create table blobtest (name varchar2(32), id integer, photo blob) tablespace users")
        c.execute("insert into blobtest values (:1, :2, EMPTY_BLOB())", \
                  "Shane Hathaway", 4)
        c.execute("insert into blobtest values (:1, :2, EMPTY_BLOB())", \
                  "Shane Hathaway #2", 5)

        lump = self._getBinary(200)

        c.execute("select * from blobtest where id>3 for update")

        for r in c.fetchall():
            
            lob = r[2]
            lob.write(lump)

        self.db.commit()

        c.execute("select * from blobtest where id>3")
        for r in c.fetchall():

            lob = r[2]
            pic = lob.read()            
            self.assertEqual(pic,
                             lump,
                             'selected binary data different from inserted binary data')
            
if __name__ == '__main__':
    unittest.main()

